/*
 *  Copyright 2001-2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package ar.uba.fi.posgrado.academy.model;

import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import ar.uba.fi.posgrado.common.model.AbstractDomainObject;
import ar.uba.fi.posgrado.common.model.Student;

/**
 * Curso
 * 
 * @author ariel.piechotka
 * 
 */

@Entity
@Table(name = "CURSO")
@SuppressWarnings("serial")
public class Course extends AbstractDomainObject {

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ID_ENTE")
	private Body body;

	@Column(name = "CODIGO", length = 10, nullable = false)
	private String code;

	@Column(name = "NOMBRE", length = 45, nullable = false)
	private String name;

	@Column(name = "CERTIFICADO", length = 255)
	private String certificate;

	@Column(name = "PLAN", nullable = false)
	private String curriculum;

	@Column(name = "PRIMERA_FECHA_PAGO", nullable = true)
	private Date firstDueDate;

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "course")
	private Set<Instalment> instalments;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ID_TIPO_CURSO")
	private CourseType courseType;

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "course")
	@Cascade( { CascadeType.SAVE_UPDATE, CascadeType.DELETE_ORPHAN })
	private Set<Resolution> resolutions;

	@ManyToMany(targetEntity = Subject.class, fetch = FetchType.LAZY)
	@JoinTable(name = "CURSO_MATERIA", joinColumns = @JoinColumn(name = "ID_CURSO", referencedColumnName = "ID"), inverseJoinColumns = @JoinColumn(name = "ID_MATERIA", referencedColumnName = "ID"))
	private Set<Subject> subjects;

	@ManyToMany(targetEntity = Student.class, fetch = FetchType.LAZY)
	@JoinTable(name = "ALUMNO_CURSO", joinColumns = @JoinColumn(name = "ID_CURSO", referencedColumnName = "ID"), inverseJoinColumns = @JoinColumn(name = "ID_ALUMNO", referencedColumnName = "ID"))
	private Set<Student> students;

	@Column(name = "CANT_MATRICULAS", nullable = false)
	private Byte qtyRegistrationFees;

	@Override
	public String[] getExcludedFields() {
		return new String[] { "body", "certificate", "curriculum",
				"firstDueDate", "instalments", "subjects", "type",
				"resolutions", "students", "courseType", "qtyRegistrationFees" };
	}

	public Body getBody() {
		return body;
	}

	public void setBody(Body body) {
		this.body = body;
	}

	public String getCertificate() {
		return certificate;
	}

	public void setCertificate(String certificate) {
		this.certificate = certificate;
	}

	public Set<Instalment> getInstalments() {
		return instalments;
	}

	public void setInstalments(Set<Instalment> instalments) {
		this.instalments = instalments;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCurriculum() {
		return curriculum;
	}

	public void setCurriculum(String curriculum) {
		this.curriculum = curriculum;
	}

	public Set<Subject> getSubjects() {
		return subjects;
	}

	public void setSubjects(Set<Subject> subjects) {
		this.subjects = subjects;
	}

	public Date getFirstDueDate() {
		return firstDueDate;
	}

	public void setFirstDueDate(Date firstDueDate) {
		this.firstDueDate = firstDueDate;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Set<Resolution> getResolutions() {
		return resolutions;
	}

	public void setResolutions(Set<Resolution> resolutions) {
		this.resolutions = resolutions;
	}

	public Set<Student> getStudents() {
		return students;
	}

	public void setStudents(Set<Student> students) {
		this.students = students;
	}

	public CourseType getCourseType() {
		return courseType;
	}

	public void setCourseType(CourseType courseType) {
		this.courseType = courseType;
	}

	public Byte getQtyRegistrationFees() {
		return qtyRegistrationFees;
	}

	public void setQtyRegistrationFees(Byte qtyRegistrationFees) {
		this.qtyRegistrationFees = qtyRegistrationFees;
	}
}
